package me.lc.linklinkchrist.sprite;

import me.lc.linklinkchrist.R;
import me.lc.linklinkchrist.core.GameManager;
import me.lc.linklinkchrist.core.GameSystem;
import me.lc.linklinkchrist.scene.GameScene;
import me.lc.linklinkchrist.scene.MainScene;
import me.lc.linklinkchrist.util.ADHelper;
import me.lc.linklinkchrist.util.AudioHelper;
import me.lc.linklinkchrist.util.GameUtil;
import android.app.Activity;

import com.wiyun.engine.nodes.Button;
import com.wiyun.engine.nodes.Node;
import com.wiyun.engine.nodes.Sprite;

public class LoseShowBlock extends Node {
	Sprite bg;
	Button btnRetry;
	Button btnReturnMenu;

	public LoseShowBlock() {
		bg = Sprite.make(GameSystem.loseBgTex);
		this.addChild(bg);

		btnRetry = Button.make(R.drawable.button_retry,
				R.drawable.button_retry, this, "onRetryButtonClicked");
		float btnY = GameSystem.loseBgTex.getHeight() * 0.285f
				- GameSystem.loseBgTex.getHeight() / 2.0f;
		this.addChild(btnRetry);
		btnRetry.setPosition(0, btnY);
		btnRetry.setClickScale(1.1f);

		btnReturnMenu = Button.make(R.drawable.button_returnmenu,
				R.drawable.button_returnmenu, this, "onReturnButtonClicked");
		float btnRetY = GameSystem.loseBgTex.getHeight() * 0.122f
				- GameSystem.loseBgTex.getHeight() / 2.0f;
		this.addChild(btnReturnMenu);
		btnReturnMenu.setPosition(0, btnRetY);
		btnReturnMenu.setClickScale(1.1f);
	}

	public void onRetryButtonClicked() {
		((Activity) GameSystem.AndroidContext).runOnUiThread(new Runnable() {
			public void run() {
				AudioHelper.clickItem();
				LoseShowBlock.this.setScale(0.5f);
				GameScene.make().startNewGame();
			}
		});
	}

	public void onReturnButtonClicked() {
		((Activity) GameSystem.AndroidContext).runOnUiThread(new Runnable() {
			public void run() {
				AudioHelper.clickItem();
				MainScene.make().showMainMenu();
				GameManager.instance.quitGame();
				GameUtil.switchSceneFlipX(MainScene.make());
				LoseShowBlock.this.setScale(0.5f);
				ADHelper.hideAd();
			}
		});
	}
}
